<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">人员性质</label>
                        <div class="layui-input-block">
                            <div id="person_nature" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">持证人</label>
                        <div class="layui-input-block">
                            <input type="text" name="person_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">签约日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="sign_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                        </div>
                    </div>
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">聘用资格</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <div id="qualification" class="xmselect_div">-->
<!--                                <div class="xmselect_title">请选择</div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">聘用渠道</label>
                        <div class="layui-input-block">
                            <div id="channel" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证件用途</label>
                        <div class="layui-input-block">
                            <div id="purpose" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">是否可驻场</label>
                        <div class="layui-input-block">
                            <select name="iszhu" id="iszhu"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">支付方式</label>
                        <div class="layui-input-block">
                            <select name="pay_type" id="pay_type"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">聘期开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="start_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">聘期结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="end_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">银行账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="account_num" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="qualification" name="qualification" value="">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <?php include 'dao.php' ?>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>
    var currButAuth, currTabData, queryStatus = 0, sea_channel = '', sea_person_nature='', sea_chanid = '', sea_qualification = '', sea_purpose = '';
    layui.use(['table','form','soulTable'], function () {
        var table = layui.table, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            sea_channel = ''; sea_person_nature=''; sea_chanid = ''; sea_qualification = ''; sea_purpose = '';
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        var height_l = $('.laytp-container').height() - 140;
        $('#tree_content').css('cssText','height:'+height_l+'px');
        $('.engindao_bac').css('cssText','height:'+height_l+'px');


        setSouTableExport('聘用合同');
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_cert_employ_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response
            ,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                if(queryStatus === 0){
                    var iszhuArr = res.data.iszhu;
                    var iszhu_str = '<option value="">请选择</option>';
                    for(var i in iszhuArr){
                        iszhu_str += '<option value="'+i+'">'+iszhuArr[i]+'</option>';
                    }
                    $('#iszhu').html(iszhu_str);

                    var pay_typeArr = res.data.pay_type;
                    var pay_type_str = '<option value="">请选择</option>';
                    for(var i in pay_typeArr){
                        pay_type_str += '<option value="'+i+'">'+pay_typeArr[i]+'</option>';
                    }
                    $('#pay_type').html(pay_type_str);

                    queryStatus = 1;
                }

                xmselect_dan('chanid', res.data.chanid, sea_chanid, function (res) {
                    sea_chanid = res.arr && res.arr.length > 0 ?  res.arr[0].value : '';
                    searchTableFunc(form, table);
                });
                xmselect_dan('person_nature', res.data.person_nature, sea_person_nature, function (res) {
                    sea_person_nature = res.arr && res.arr.length > 0 ?  res.arr[0].value : '';
                    searchTableFunc(form, table);
                });
                xmselect_dan('channel', res.data.channel, sea_channel, function (res) {
                    sea_channel = res.arr && res.arr.length > 0 ? res.arr[0].value : '';
                    searchTableFunc(form, table);
                });
                xmselect_dan('purpose', res.data.purpose, sea_purpose, function (res) {
                    sea_purpose = res.arr && res.arr.length > 0 ? res.arr[0].value : '';
                    searchTableFunc(form, table);
                });
                // xmselect_dan('qualification', res.data.qualification, sea_qualification, function (res) {
                //     sea_qualification = res.arr && res.arr.length > 0 ? res.arr[0].value : '';
                //     searchTableFunc(form, table);
                // });

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'person_name', title: '持证人', minWidth: 100,event:'person_name',templet:function (e) {
                        return '<span class="colorlan">'+e.person_name+'</span>';
                    }}
                ,{field: 'person_nature', title: '人员性质'}
                ,{field: 'chan_name', title: '所属单位', minWidth: 100}
                ,{field: 'number', title: '合同编号', minWidth: 100}
                ,{field: 'channel', title: '聘用渠道'}
                ,{field: 'sign_dt', title: '签约日期'}
                ,{field: 'qualification', title: '聘用资格'}
                ,{field: 'purpose', title: '证件用途'}
                ,{field: 'iszhu_name', title: '是否可驻场'}
                ,{field: 'pay_type', title: '支付方式'}
                ,{field: 'money', title: '聘费(元)'}
                ,{field: 'start_dt', title: '聘费开始时间'}
                ,{field: 'end_dt', title: '聘费结束时间'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);

            }
        });

        listTableSearch(form, table);

        table.on('tool(datalist)', function(obj){
            var data = obj.data;
            if(obj.event === 'person_name'){
                openPage('../cert_person/show.php?id='+data.personid);
            }
        });
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_cert_employ_del, {id:trData.id});
    }
    function auth_but_func_import(buttitle){
        openPage('../public/import.php?url='+ask_import_cert_empoly+'&down='+encodeURI('外聘')+'&daolei=1', '770px', '490px');
    }
    function auth_but_func_muldel(buttitle){
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        data_delete(ask_cert_employ_del, {id: idArr.join(',')});
    }
</script>
</body>
</html>
